//
//  HYBLoadingImageView.swift
//  mysigndemo
//
//  Created by dengwei on 16/6/2.
//  Copyright © 2016年 dengwei. All rights reserved.
//

import UIKit

typealias HYBImageLoadingCompletion = (image: UIImage?) -> ();
typealias HYBImageCompletion = (image: UIImage?, isFromCache: Bool) -> ();

///
class HYBLoadingImageView: UIImageView {
    
    convenience init() {
        self.init(frame: CGRectZero);
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        
        self.clipsToBounds = true;
        self.layer.masksToBounds = true;
        self.contentMode = UIViewContentMode.ScaleAspectFill;
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder);
        
        self.clipsToBounds = true;
        self.layer.masksToBounds = true;
        self.contentMode = UIViewContentMode.ScaleAspectFill;
    }
    
    ///
    /// 是否将图片控件显示为圆形
    ///
    /// isCircle true表示显示为圆
    ///
    func isCircle(isCircle: Bool = true) {
        if isCircle == true {
            let width = min(self.frame.size.width, self.frame.size.height);
            self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, width, width);
            self.layer.cornerRadius = width / 2;
        }
    }
    
}